#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>
typedef int DataType;
typedef struct BinaryTreeNode
{
	DataType x;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}BinaryTreeNode;
BinaryTreeNode* BuyNode(int n)
{
	BinaryTreeNode* newnode = (BinaryTreeNode*)malloc(sizeof(BinaryTreeNode));
	if (newnode == NULL)
	{
		perror("MALLOC FAIL");
		exit(1);
	}
	newnode->x = n;
	newnode->left = newnode->right = NULL;
	return newnode;
}
BinaryTreeNode* CreatNode()
{
	BinaryTreeNode* node1 = BuyNode(1);
	BinaryTreeNode* node2 = BuyNode(2);
	BinaryTreeNode* node3 = BuyNode(3);
	BinaryTreeNode* node4 = BuyNode(4);
	BinaryTreeNode* node5 = BuyNode(5);
	BinaryTreeNode* node6 = BuyNode(6);
	BinaryTreeNode* node7 = BuyNode(7);
	

	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;
	node5->right = node7;
	return node1;
}
int NodeSize(BinaryTreeNode* root)
{
	
	return root == NULL? 0 : NodeSize(root->left) + NodeSize(root->right)+1;
}
int TreeLeafSize(BinaryTreeNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	if (root->left == 0 && root->right == 0)
	{
		return 1;
	}
	return TreeLeafSize(root->left) + TreeLeafSize(root->right);
}
int TreeHeight(BinaryTreeNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	//if (root->left == 0 && root->right == 0)
	//{
	//	return 1;
	//}
	int LeftHeight = TreeHeight(root->left);
	int RightHeight = TreeHeight(root->right);
	return  LeftHeight > RightHeight ? LeftHeight+1 : RightHeight+1;
}
int FloorNode(BinaryTreeNode* root, int k)
{
	if (root == NULL)
	{
		return 0;
	}
	if (k == 1)
	{
		return 1;
	}
	return FloorNode(root->left, k - 1) + FloorNode(root->right, k - 1);
}
bool isUnivalTree(BinaryTreeNode* root)
{
	if (root == NULL)
	{
		return true;
	}
	if (root->left && root->left->x != root->x)
	{
		return false;
	}
	if (root->right && root->right->x != root->x)
	{
		return false;
	}
	return isUnivalTree(root->left) && isUnivalTree(root->right);
}
int main()
{
	BinaryTreeNode* root=CreatNode();
	/*int x=NodeSize(root);*/
	//int x = TreeHeight(root);
	int x = FloorNode(root, 3);
	printf("%d", x);
	return 0;
}